package org.sci4j.maths;

/**
 *   sci4j - Java library for scientific computation.
 *   
 *   Copyright (C) 2010 Inaki Ortiz de Landaluce
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
public final class Complex {

	public double re, im;
	
	public Complex(double r, double i) {
		this.re = r;
		this.im = i;
	}
	
	public Complex assign(Complex z) {
		this.re = z.re;
		this.im = z.im;
		return this;
	} 
	
	public Complex plus(Complex z) {
		return new Complex(this.re + z.re, this.im + z.im);
	}
	
	public Complex minus(Complex z) {
		return new Complex(this.re - z.re, this.im - z.im);
	}

	public Complex times(Complex z) {
		return new Complex(this.re * z.re - this.im * z.im, this.im * z.re + this.re * z.im );
	}
	
	public Complex times(double x) {
		return new Complex(this.re * x, this.im * x);
	}
	
	public Complex plusAssign(Complex z) {
		this.re += z.re;
		this.im += z.im;
		return this;
	}
}
